import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/details',
        name: 'main',
        redirect: '/details',
        component: () => import(/* webpackChunkName: "about" */ '../views/main.vue'),
        children: [
            {
                path: '/details',
                name: 'details',
                component: () => import(/* webpackChunkName: "about" */ '../views/details.vue')
            }, {
                path: '/user',
                name: 'user',
                component: () => import(/* webpackChunkName: "about" */ '../views/user.vue')
            }, {
                path: '/course',
                name: 'course',
                component: () => import(/* webpackChunkName: "about" */ '../views/course.vue')
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },

    {
        path: '/sign',
        name: 'sign',
        component: () => import(/* webpackChunkName: "about" */ '../views/sign.vue')
    },
    {
        path: '/kbList',
        name: 'kbList',
        component: () => import(/* webpackChunkName: "about" */ '../views/kbList.vue')
    },
    {
        path: '/smsList',
        name: 'smsList',
        component: () => import(/* webpackChunkName: "about" */ '../views/smsList.vue')
    }, {
        path: '/adminvideo',
        name: 'adminvideo',
        component: () => import(/* webpackChunkName: "about" */ '../views/adminvideo.vue')
    }, {
        path: '/dy',
        name: 'dy',
        component: () => import(/* webpackChunkName: "about" */ '../views/dy.vue')
    },
    {
        path: "*",
        redirect: "/sign",
    },
]

const router = new VueRouter({
    routes
})
let noLoginPage = ["sign"]
router.beforeEach((to, from, next) => {
    if (!noLoginPage.includes(to.name)) {
        if (!localStorage.getItem("pandaSms_user")) {
            next('/sign');
        }
    }
    next();
});

export default router
